<?php

class Admin_review_Controller extends Base_Controller {

	public $restful = true;
	public $_data = array();

    public function post_del() 
	{
        $id = Input::get('id');
        $reviewModel = new ReviewLogic();
        $this->_data["state"] = $reviewModel->deleteReviewByID($id);
		if($this->_data["state"] == 1) $this->_data["state"]=true;
		else $this->_data["state"]=false;

		echo Response::json(array("state"=>$this->_data['state']));

	}
    public function action_add() {
        if (!Input::has('video_id') || !Input::has('text')) {
            return Response::json(
                            array(
                                'errno' => UMSErrcode::PARA_ERR,
            ));
        }
        $video_id = Input::get('video_id');
        $user_id = Input::get('user_id', intval(session::get('user_id')));
        $author = Input::get('author', session::get('username'));
        $text = Input::get('text');
        $rating = Input::all('rating', 50);
        $reviewModel = new ReviewLogic();
        $ret = $reviewModel->insertReview($video_id, $user_id, $author, $text, $rating);
        unset($reviewModel);
        if ($ret) {
            return Response::json(array(
                        'errno' => UMSErrcode::SUCCESS,
            ));
        } else {
            return Response::json(
                            array(
                                'errno' => UMSErrcode::SYS_ERR,
            ));
        }
    }

    public function get_index() {

        $per_page = intval(Input::get('per_page', 20));
        $reviewModel = new ReviewLogic();
	$ret = $reviewModel->list_Reviews($per_page);
	return View::make('admin.review.list')->with("reviews_list",$ret);


    }
    public function action_list() {

        if (!Input::has('video_id')) {
            return Response::json(
                            array(
                                'errno' => UMSErrcode::PARA_ERR,
            ));
        }
        $video_id = intval(Input::get('video_id'));
        $per_page = intval(Input::get('per_page', 20));
        $reviewModel = new ReviewLogic();
        $ret = $reviewModel->getReviewByVideoID($video_id, $per_page);
        return Response::json($ret);
    }

}

?>
